#include "sdlutil.hpp"

void set_pixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
	if(x>0 && y>0)
	{
		Uint8 *target_pixel = (Uint8 *)surface->pixels + y * surface->pitch + x * 4;
		*(Uint32 *)target_pixel = pixel;
	}
}

void draw_rect(SDL_Surface *surface, int x, int y, int w, int h, Uint32 pixel, bool fill)
{
	if(fill==true)
	{
		for(int i = 0; i<w; i++)
		{
			for(int j = 0; j<h; j++)
			{
				set_pixel(surface, x+i, y+j, pixel);
			}
		}
	}
	else
	{
		for(int j = 0; j<w; j++)
		{
			set_pixel(surface, x+j, y, pixel);
			set_pixel(surface, x+j, y+h, pixel);
		}
		for(int j = 0; j<h; j++)
		{
			set_pixel(surface, x, y+j, pixel);
			set_pixel(surface, x+w, y+j, pixel);
		}

	}
}